package com.qys.livesMall.app.user.controller.app;


import com.qys.livesMall.app.user.model.vo.UserBalanceDetailVO;
import com.qys.livesMall.app.user.service.IH2AppUserBalanceLogService;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.finance.model.dto.AccountDetailSearch;
import com.qys.livesMall.finance.model.dto.AccountInOut;
import com.qys.livesMall.finance.service.FinanceUserAccountDetailService;
import com.qys.livesMall.framework.utils.SecurityUtils;
import com.qys.livesMall.framework.view.QysPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Locale;

/**
 *app-用户余额变动记录
 */
@RestController
@RequestMapping("/app/user/balance/log")
@Tag(name = "用户余额变动记录", description = "用户余额变动记录")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class AppUserBalanceLogController {

    private final IH2AppUserBalanceLogService userBalanceLogService;

    private final FinanceUserAccountDetailService financeUserAccountDetailService;

    /**
     * 列表
     * @param search
     * @return
     */
    @PostMapping("/page")
    @Operation(summary = "用户余额变动记录信息")
    public R<QysPage<UserBalanceDetailVO>> page(@RequestBody AccountDetailSearch search) {
        search.setUserId(SecurityUtils.getUserId());
        if (search.getPageSize()>=50){
            return R.fail("Page out max length");
        }
        return R.ok(userBalanceLogService.pageByApp(search,SecurityUtils.getLanguage()));
    }

    /**
     * 统计
     * @param search
     * @return
     */
    @PostMapping("/sum")
    public R<AccountInOut> sum(@RequestBody AccountDetailSearch search){
        search.setUserId(SecurityUtils.getUserId());
        AccountInOut inOut=financeUserAccountDetailService.sum(search);
        if (inOut==null){
            inOut=new AccountInOut();
        }
        return R.ok(inOut);
    }
}
